import { PageParams } from '@/api/model/pageParams';
import { request } from '@/utils/request';

const page = async (params: PageParams) => {
  return request.post({
    url: '/sysPermission/page',
    data: params,
  });
};

const tree = async () => {
  return request.get({
    url: '/sysPermission/tree',
  });
};

const insertApi = async (data: any) => {
  return request.post({
    url: '/sysPermission/insert',
    data,
  });
};

const updateApi = async (data: any) => {
  return request.post({
    url: '/sysPermission/update',
    data,
  });
};

const deleteById = async (id: string) => {
  return request.get({
    url: `/sysPermission/delete/${id}`,
  });
};

const getPermissionByRoleId = async (roleId: number) => {
  return request.get({
    url: `/sysPermission/getPermissionByRoleId/${roleId}`,
  });
};

const assignPermission = async (data: { roleId: number; check: boolean; permissionIds: string[] }) => {
  return request.post({
    url: '/sysPermission/assignPermission',
    data,
  });
};

export { assignPermission, deleteById, getPermissionByRoleId, insertApi, page, tree, updateApi };
